package com.game;


import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.Window;
import android.view.WindowManager;


public class PlayScene  extends Activity
{
	private static final String MYTAG = "GAISMA";
	private Builder alertNewGame;
    private Builder alertSaveAndQuit;

	
    private GameView gameView;
	
	public void onCreate(Bundle icicle)
	{
	    super.onCreate(icicle);	      
	    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
        		WindowManager.LayoutParams.FLAG_FULLSCREEN);
	   // setContentView(R.layout.play_scene);
        gameView = new GameView(this);
	    setContentView(gameView);
	    setupAlerts();
	    Log.i(MYTAG, "Got here!!!!");
	      
	}
	
	public boolean onCreateOptionsMenu(Menu menu) 
	{
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.principal_menu, menu);
        return true;
    }
	
	public boolean onOptionsItemSelected (MenuItem item)
	{

		switch (item.getItemId())
		{
			case R.id.playNewGameMenuButton:
				Log.i(MYTAG, "Pressed playNewGameMenuButton!!!!");
				alertNewGame.show();
			return true;

			case R.id.playQuitMenuButton:
				Log.i(MYTAG, "Pressed playQuitMenuButton!!!!");
				alertSaveAndQuit.show();
			return true;

		}

		return false;
	}

	private void setupAlerts()
	{
		alertNewGame = new AlertDialog.Builder(this)
        .setTitle("")
        .setMessage("Do you realy want to restart? Progress will be lost")
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                	RestartGame();
                }
        })
        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                        //Put your code in here for a negative response
                		// Do nothing
                }
        });
		
		alertSaveAndQuit = new AlertDialog.Builder(this)
        .setTitle("")
        .setMessage("Really want to quit?")
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                	SaveAndQuitGame();
                }
        })
        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                        //Put your code in here for a negative response
                		// Do nothing
                }
        });
	}
	
	private void RestartGame()
	{
		Intent i = new Intent(PlayScene.this, Gaisma.class);
        startActivity(i);		
	}
	
	private void SaveAndQuitGame()
	{
		setResult(RESULT_OK);
        finish();		
	}

	


}
